package cn.net.zyx.controller;

import cn.net.zyx.domain.Video;
import cn.net.zyx.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * description: VideoController <br>
 * date: 2021/5/7 09:37 <br>
 *
 * @author: ZhangYixin <br>
 * version: 1.0 <br>
 */
@RestController
@RequestMapping("api/v1/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @RequestMapping("find_by_id")
    public Object findById(int videoId , HttpServletRequest request){
        Video video = videoService.findById(videoId);
        video.setServerInfo(request.getServerName()+":"+request.getServerPort());
        return video;
    }

    @PostMapping("save")
    public int save (@RequestBody Video video){
        if (video == null) {
            return 0;
        }else {
            System.out.println(video.getTitle());
            return 1;
        }
    }

}
